﻿#ifndef VIDEOEFFECT_H
#define VIDEOEFFECT_H

#include "globalinstance.h"
#include <QBasicTimer>
#include <QMutex>
#include <QPixmap>
#include <QSharedPointer>
#include <qwindowdefs.h>

class QFrame;

class VideoEffect : public QObject, public GlobalInstance<VideoEffect>
{
    Q_OBJECT
    friend class GlobalInstance<VideoEffect>;
    VideoEffect();
public:
    enum EffectFlag
    {
        NoEffect,
        ScreenEffect,
#ifdef Q_OS_WIN
        WindowEffect
#endif
    };
    enum PIPFlag
    {
        NoPIP,
        EffectInCamera,
        CameraInEffect
    };

    //mutex area
    QPixmap &captureImage();
    void clearCaptureImage();
    EffectFlag effFlag;
    PIPFlag pipFlag;
    QMutex mutex;

    void startCapture(const QSize &size);
    QFrame *capture;

#ifdef Q_OS_WIN
    bool chooseWid(QWidget *currentWidget);
    void startCaptureWindow();
    void endCaptureWindow();
    HWND wId;
#endif

    void endCapture();
    void endEffect();
protected:
    void timerEvent(QTimerEvent *e);
private slots:
    void captureFrameShown();
    void captureFrameDeleted();
private:
    void moveAndCapture();
    QPixmap capturePixmap;
    QBasicTimer screen_capture_timer;
#ifdef Q_OS_WIN
    QBasicTimer window_capture_timer;
#endif
    QPixmap cursor_image;
};

#endif // VIDEOEFFECT_H
